/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.intec.matsab.persistence;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Sabrina
 */
@Entity
@Table(name = "Pensum")
@NamedQueries({
    @NamedQuery(name = "Pensum.findAll", query = "SELECT p FROM Pensum p"),
    @NamedQuery(name = "Pensum.findByIdPensum", query = "SELECT p FROM Pensum p WHERE p.pensumPK.idPensum = :idPensum"),
    @NamedQuery(name = "Pensum.findByIdCarrera", query = "SELECT p FROM Pensum p WHERE p.pensumPK.idCarrera = :idCarrera"),
    @NamedQuery(name = "Pensum.findByFecha", query = "SELECT p FROM Pensum p WHERE p.fecha = :fecha")
})
public class Pensum implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected PensumPK pensumPK;
    
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.DATE)
    private Date fecha;

    @Basic(optional = false)
    @Lob
    @Column(name = "pensum")
    private byte[] pensum;
    //@OneToMany(cascade = CascadeType.ALL, mappedBy = "pensum")
    //private Collection<Estudiante> estudianteCollection;
    @JoinColumn(name = "idCarrera", referencedColumnName = "idCarrera", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Carrera carrera;

    public Pensum() {
    }

    public Pensum(PensumPK pensumPK) {
        this.pensumPK = pensumPK;
    }

    public Pensum(PensumPK pensumPK, Date fecha, byte[] pensum) {
        this.pensumPK = pensumPK;
        this.fecha = fecha;
        this.pensum = pensum;
    }

    public Pensum(int idPensum, String idCarrera) {
        this.pensumPK = new PensumPK(idPensum, idCarrera);
    }

    public PensumPK getPensumPK() {
        return pensumPK;
    }

    public void setPensumPK(PensumPK pensumPK) {
        this.pensumPK = pensumPK;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public byte[] getPensum() {
        return pensum;
    }

    public void setPensum(byte[] pensum) {
        this.pensum = pensum;
    }

    /*
    public Collection<Estudiante> getEstudianteCollection() {
        return estudianteCollection;
    }

    public void setEstudianteCollection(Collection<Estudiante> estudianteCollection) {
        this.estudianteCollection = estudianteCollection;
    }
     */
    
    public Carrera getCarrera() {
        return carrera;
    }

    public void setCarrera(Carrera carrera) {
        this.carrera = carrera;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pensumPK != null ? pensumPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pensum)) {
            return false;
        }
        Pensum other = (Pensum) object;
        if ((this.pensumPK == null && other.pensumPK != null) || (this.pensumPK != null && !this.pensumPK.equals(other.pensumPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.intec.matsab.persistence.Pensum[pensumPK=" + pensumPK + "]";
    }
}
